package pack.findthewords;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;

public class Title extends Activity {

    private static final String BUGSENSE_APIKEY="xxxxx";
    private static final String PARSE_APP_ID="2dkhAEtnyEA0Yok1MeBdzoBFhms9VRfk1K5YOMLt";
    private static final String PARSE_CLIENT_KEY="rMUxPw1dkdQPfJDPq0B1yYO1SmhT1aLiBe89VsNT";

    Animation animBounce;
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.title);

	Typeface tf=Typeface.createFromAsset(getAssets(), "fonts/title.ttf");
	tv=(TextView) findViewById(R.id.titleBluePixel);
	tv.setTypeface(tf);
	tv.setTextSize(60);

	// Parse init
	Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
	PushService.setDefaultPushCallback(this, Title.class);
	ParseInstallation.getCurrentInstallation().saveInBackground();
	ParseAnalytics.trackAppOpened(getIntent());

	startAnim();
    }

    private void startAnim() {
	final int welcomeScreenDisplay=2000;
	runOnUiThread(bounceAnimation);

	Thread welcomeThread=new Thread() {
	    int wait=0;

	    @Override
	    public void run() {
		try {
		    super.run();
		    while (wait < welcomeScreenDisplay) {
			sleep(100);
			wait+=100;
		    }

		}
		catch (Exception e) {
		    startActivity(new Intent(Title.this, Splash.class));
		    finish();
		}
		finally {
		    startActivity(new Intent(Title.this, Splash.class));
		    finish();
		}
	    }
	};
	welcomeThread.start();

    }

    private final Runnable bounceAnimation=new Runnable() {
	@Override
	public void run() {
	    animBounce=AnimationUtils.loadAnimation(getApplicationContext(), R.animator.bounce);
	    tv.startAnimation(animBounce);
	}
    };
}
